import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {AppRoutingModule} from './app-routing.module';
import {AppComponent} from './app.component';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {HTTP_INTERCEPTORS, HttpClient, HttpClientModule} from '@angular/common/http';
import {APP_BASE_HREF} from '@angular/common';
import {PrimeNGModule} from './primeng.module';
import {FormsModule, ReactiveFormsModule} from '@angular/forms';
import {ConfirmationService, MessageService} from 'primeng/api';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
import {EventService} from './pages/basic/commons/event.service';
import {LoginComponent} from './pages/basic/login/login.component';
import {Authentication} from './pages/basic/auth/authentication';
import {AuthService} from './pages/basic/auth/auth.service';
import {PermissionInterceptor} from './pages/basic/commons/permission.interceptor';

export function createI18NLoader(httpClient: HttpClient) {
    return new TranslateHttpLoader(httpClient, './assets/i18n/', '.json');
}

export const httpInterceptorProviders = [
    { provide: HTTP_INTERCEPTORS, useClass: PermissionInterceptor, multi: true },
];

@NgModule({
    declarations: [
        AppComponent,
        LoginComponent,
    ],
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        HttpClientModule,
        FormsModule,
        ReactiveFormsModule,
        PrimeNGModule,
        AppRoutingModule,
        TranslateModule.forRoot({
            loader: {
                provide: TranslateLoader,
                useFactory: (createI18NLoader),
                deps: [HttpClient]
            }
        })
    ],
    bootstrap: [AppComponent],
    providers: [
        {provide: APP_BASE_HREF, useValue: '/'},
        // httpInterceptorProviders,
        EventService,
        MessageService,
        ConfirmationService,
        Authentication,
        AuthService
    ]
})
export class AppModule {
}
